package com.easy.dfc.web;

import com.alibaba.fastjson.JSONObject;
import com.easy.common.bean.Result;
import com.easy.common.constant.EnumConfig;
import com.easy.core.web.BaseController;
import com.easy.dfc.Utils.Error;
import com.easy.dfc.Utils.JsonUtil;
import com.easy.dfc.Utils.Util;
import com.easy.dfc.entity.AnswerQuestion;
import com.easy.dfc.entity.AskOther;
import com.easy.dfc.entity.ReplyAnswer;
import com.easy.dfc.entity.UserPara;
import com.easy.dfc.service.AskOtherService;
import com.easy.dfc.service.DealerHomeService;
import com.easy.dfc.service.UsersetService;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.Date;
import java.util.List;

@Controller
@RequestMapping(value = "${apiPath}/DealerHome")
public class DealerHomeController extends BaseController {

    @Resource
    private DealerHomeService dealerHomeService;

    /**
     * 买家版首页
     * @param model
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "HomePage")
    public Result HomePage(Model model) {
        try {
            return dealerHomeService.HomePage();
        } catch (Exception e) {
            logger.error(e.toString());
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.DB_ERROR);
            return rt;
        }
    }

    /**
     * 买家版首页
     * @param user userId,token
     * @param model
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "NiceProduct", method = RequestMethod.POST)
    public Result NiceProduct(@RequestBody UserPara user, Model model) {
        try {
            //if (!usersetService.VerifyToken(user.getUserId(), user.getToken())) {
            //    Result rt = new Result();
            //    rt.setStatus(EnumConfig.S_CODE.FAIL);
            //    return rt;
            //}
            return dealerHomeService.NiceProduct(user.getPageIndex(),user.getPageSize());
        } catch (Exception e) {
            logger.error(e.toString());
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.FAIL);
            return rt;
        }
    }
}
